//
//  VisitorLogingView.swift
//  sina
//
//  Created by lixuelei on 6/10/15.
//  Copyright © 2015 itcast. All rights reserved.
//

import UIKit

//1.1起草一个代理协议.1.2声明一个代理
protocol VisitorLogingViewDelegate: NSObjectProtocol{
    
    //注册
    func visitorZC()
    //登陆
    func visitorDL()

}


class VisitorLogingView: UIView {
    
    //声明一个代理.为了防止循环引用 需要使用weak
    weak var visitorLoginDelegate: VisitorLogingViewDelegate?
    @IBOutlet weak var small: UIImageView!
    
    @IBOutlet weak var zhezhao: UIImageView!

    @IBOutlet weak var icon: UIImageView!
    @IBOutlet weak var label: UILabel!
    
    func setUIInfo(imageName name: String,textName: String,isHome:Bool = false){
    
        icon.image = UIImage(named: name)
        label.text = textName
        small.hidden = !isHome
        if isHome{
            start()
        }
    
    }
    
    //MARK:home动画
    func start(){
        let anima = CABasicAnimation(keyPath: "transform.rotation")
        //是否重复
        anima.repeatCount = MAXFLOAT
        //转一圈的时间
        anima.duration = 20
        //旋转范围
        anima.toValue = 2 * M_PI
        //动画处于非活跃状态的时候会默认移除图层,设为假就不移除,动画不受跳转界面影响
        anima.removedOnCompletion = false
        
        //添加到旋转图层
        small.layer .addAnimation(anima, forKey: nil)
        
    
    }
    
    
    
    
    
    
    @IBAction func login(sender: AnyObject) {
            visitorLoginDelegate?.visitorDL()
        
        
    }
    
    
    @IBAction func zhuce(sender: AnyObject) {
        visitorLoginDelegate?.visitorZC()
    }
    
    
    
    
    
    
    
    
    
    
    
    
}
